package com.thitech.sif.interceptor;

import com.thitech.sif.AbsOutput;
import com.thitech.sif.Executor;
import com.thitech.sif.ReqAndResContext;
import com.thitech.sif.utils.log.LogBuilder;

/**
 * 服务调用输入输出日志记录
 * @author shisheng.lian
 * @date 2014-08-06
 * 
 */
public class LogInterceptor extends AbsInterceptorHandler {

	@Override
	public boolean beforeInvoke(Executor executor)
			throws Exception {
		return true;
	}

	@Override
	public void afterInvoke(Executor executor, AbsOutput output, Throwable e) throws Exception {
		ReqAndResContext ctx = ReqAndResContext.currentContext();
		String request = ctx.getRequest();
		String response = ctx.getResponse();
		getLogger().info(LogBuilder.getLogMsg(executor, "Request：" + request));
		getLogger().info(LogBuilder.getLogMsg(executor, "Response：" + response));
	}

	@Override
	public void destroy() {
		ReqAndResContext.remove();
	}

}
